import { ADD_ITEM, DEL_ITEM, INPUT_ITEM, GET_LIST, GET_MY_LIST } from "@/store/actionTypes"
import axios from 'axios'

export const inputAction = (value) => ({
  type: INPUT_ITEM,
  value
})

export const addItemAction = (key) => ({
  type: ADD_ITEM,
  key
})

export const deleteItemAction = (idx) => ({
  type: DEL_ITEM,
  idx
})

export const getListAction = (data) => ({
  type: GET_LIST,
  data
})

export const getTodoList = () => {
  return (dispatch) => {
    //  请求地址和mockData.js里的一样
    axios.get('/data', { dataType: 'json' }).then(res => {
      let data = res.data
      const action = getListAction(data)
      dispatch(action)
    })
  }
}

export const getMyListAction = () => ({
  type: GET_MY_LIST
})